﻿@{
    ViewBag.Title = "分站长勾选日报表";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}

<script type="text/javascript">
    var Materials = new Array();

    $(document).ready(function () {

        initPickTaskGrid();
    });


    function initPickTaskGrid() {

        $('#txtStartTime').datebox("setValue", $.GetNDayAgo(4)); //默认取4任务的。
        $('#txtEndTime').datebox("setValue", $.GetYesterday()); //默认取昨天任务的。


        $('#txtCheckStartTime').datebox("setValue", $.GetToday());  //默认取今天现在。

        //$('#txtStartTime').datebox("setValue", "2015-12-28"); //日报的日期
        //$('#txtCheckStartTime').datebox("setValue", "2015-12-28"); //分站长勾选的日期

        //如果权限是可查全部的，就给分中心分站的筛选条件
        if (CenterCode == '') {

            EUIcombobox("#txtPickCenter", {
                url: '@Url.Content("~/Medical/GetCenter/")',
                valueField: 'ID',
                textField: 'Name',
                //prompt: '--请选择--',
                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }],
                onSelect: function (rec) {
                    var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                    EUIcombobox("#txtPickStation", {
                        url: urlstation,
                        valueField: 'ID',
                        textField: 'Name',
                        //prompt: '--请选择--',
                        editable: false,
                        OneOption: [{
                            ID: "",
                            Name: "--请选择--"
                        }]
                    });
                }
            });
        }
            //如果权限不是全部可查看，就将分中心赋值所属分中心
        else {

            EUIcombobox("#txtPickCenter", {
                url: '@Url.Content("~/Medical/GetCenter/")',
                valueField: 'ID',
                textField: 'Name',
                //prompt: '--请选择--',
                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            $("#txtPickCenter").combobox('setValue', CenterCode);

        }

        var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + CenterCode;
        $.EUIcombobox("#txtPickStation", {
            url: urlstation,
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]
        });

        PickTaskGrid(); //加载datagrid列表数据

    } //初始化结束
    $(window).resize(function () {
        $.setGridWithSearchBar("#TableForm", "#tbb", "#PickTaskList");
    });

    var StationCode = '@ViewData["StationCode"]'; //根据登录人的工号获取到调度中所在分站的分站编码
    var CenterCode = '@ViewData["CenterCode"]';
    var PickworkID = '@ViewData["PickworkID"]';

    function rePickTaskGrid() {

        $('#PickTaskList').datagrid({
            pageNumber: 1,
            queryParams: {
                ReportDate: $("#txtStartTime").datebox('getValue'),
                ReportDateEnd: $("#txtEndTime").datebox('getValue'),
                PickCenter: $("#txtPickCenter").combobox('getValue'),
                PickStation: $("#txtPickStation").combobox('getValue'),
                PickWorkID: $("#txtPickWorkID").textbox('getValue')
            }
        });
    }


    function PickTaskGrid() {   //加载datagrid列表数据
        $('#PickTaskList').datagrid({
            width: 'auto',
            height: 'auto',
            fitColumns: false,
            collapsible: true,
            singleSelect: false,
            selectOnCheck: true, //如果为true，单击复选框将永远选择行。
            checkOnSelect: true,  //如果为true，当用户点击行的时候该复选框就会被选中或取消选中。
            pageSize: 15,//设置 页容量5
            pageList: [10, 15, 20],//设置 页容量下拉框
            loadMsg: '数据加载中,请稍后……',
            url: '@Url.Content("~/DD/DriverReport/GetStationReportMain")',
            rownumbers: true,//显示页码，
            pagination: true,//启用分页，默认每页10行
            queryParams: {
                ReportDate: $("#txtStartTime").datebox('getValue'),
                ReportDateEnd: $("#txtEndTime").datebox('getValue'),
                PickCenter: $("#txtPickCenter").combobox('getValue'),
                PickStation: $("#txtPickStation").combobox('getValue'),
                PickWorkID: $("#txtPickWorkID").textbox('getValue')
            },
            columns: [[
            { field: "ck", checkbox: true },
            { field: "ID", hidden: true },

            { field: "StationName", title: "分站", width: '5%', align: "center", sortable: false, resizable: false },
             { field: "AgentWorkID", title: "填写人工号", width: '6%', align: "center" },
             { field: "FillState", title: "日报状态", width: '12%', align: "center" },
            { field: "AmbulanceNumber", title: "车辆", width: '9%', align: "center" },
              { field: "ReportDate", title: "日报日期", width: '9%', align: "center", formatter: $.formatDate },
              { field: "BanCi", title: "班次", width: '6%', align: "center" },
              { field: "TaskTimes", title: "车次", width: '8%', align: "center" },
             { field: "LastModifyTime", title: "最后填写时间", width: '13%', align: "center", formatter: $.formatTime },
                { field: "LastModifier", title: "最后填写人", width: '8%', align: "center" },
                 { field: "PaidMoney", title: "实际收费", width: '6%', align: "center" },
                  {
                      field: "detail", title: "查看明细", width: '8%', align: "center",
                      formatter: function (value, row, index) {

                          return '<a  class="linkURLcls" onclick="OpenCheckDetail(\'' + row.ID + '\');"  href="javascript:void(0)">查看明细</a>';
                      }
                  }
            ]],
            toolbar: [
                 {
                     id: 'btnRevisitView',
                     text: '选中[0]个',
                     iconCls: 'icon-custom-cGoods',
                     iconWidth: 22,
                     handler: function () {
                         if (Materials.length > 0) {
                             submitRevisitDetailForm(); //提交
                         }
                     }
                 }
            ],
            onCheck: function (index, row) {
                if (Materials.length == 0) {
                    Materials.push(row);
                    changeRevisitViewNum();
                    return;
                }
                var boolContain = false;
                $.each(Materials, function (i, info) {
                    if (info.ID == row.ID) {
                        boolContain = true;
                    }
                });
                if (!boolContain) {
                    Materials.push(row);
                }
                changeRevisitViewNum();

            },
            onUncheck: function (index, row) {
                var obj;
                $.each(Materials, function (i, info) {
                    if (info.ID == row.ID) {
                        obj = info;
                    }
                });
                Materials.remove(obj);
                changeRevisitViewNum();
            },
            onCheckAll: function (rows) {
                $.each(rows, function (i, infos) {
                    // var arr = ["xml", "html", "css", "js"];
                    //   $.inArray("js", arr);  //返回 3,
                    //  如果不包含在数组中, 则返回 - 1;

                    var hasmates = false;
                    $.each(Materials, function (index, mates) {
                        if (infos.ID == mates.ID) {
                            hasmates = true;
                        }
                    });
                    // if (Materials.indexOf(rows[ii]) < 0) {  //index用法只能用于string之间，不可以用于数组。
                    if (!hasmates)
                    { Materials.push(infos); }
                }
                );
                changeRevisitViewNum();
            },
            onUncheckAll: function (rows) {
                var obj;
                $.each(rows, function (i, infos) {
                    $.each(Materials, function (index, mates) {
                        if (infos.ID == mates.ID) {
                            //if ($.inArray(rows[i], Materials)>=0){
                            obj = infos;
                        }
                    });
                    Materials.remove(obj);

                    changeRevisitViewNum();
                });
            },
            onLoadSuccess: function (data) {

                var rows = $('#PickTaskList').datagrid('getRows');
                if (rows.length == 0) {
                    $.messager.alert('系统提示', '当前日期无数据，或已被全部勾选！', 'info', function () {
                    });
                }
                else {
                    $.messager.show({
                        title: '系统提示',
                        msg: '   成功加载出 ' + data.total + ' 条任务信息！'
                    });
                }
                setViewNumCheck();
                // changeDeliveryViewNum();

                $('.linkURLcls').linkbutton({
                    text: '查看明细',
                    plain: true,
                    iconCls: 'icon-search'
                });


            }

        });
        $.setGridWithSearchBar("#TableForm", "#tbb", "#PickTaskList");
    }

    function setViewNumCheck() { //自动勾选已经存在的内容
        var rows = $('#PickTaskList').datagrid('getRows');
        $.each(rows, function (index, item) {
            $.each(Materials, function (i, info) {
                if (item.ID == info.ID) {
                    $('#PickTaskList').datagrid('checkRow', index);
                }
            });
        });
    }

    //切换datagrid工具栏数字颜色
    function changeRevisitViewNum() {
        if (Materials.length == 0) {
            $("#btnRevisitView").linkbutton({
                text: "点击提交[" + Materials.length + "]个",
                iconCls: "icon-custom-cGoods"
            });

            //$('#txtTaskDate').datebox('readonly', false);

        } else if (Materials.length > 0) {
            $("#btnRevisitView").linkbutton({
                text: "点击提交[<strong><span style='color:red'>" + Materials.length + "</span></strong>]个",
                iconCls: "icon-custom-cGoodsFull"
            });
            //$('#txtTaskDate').datebox('readonly', true);
        }
    }


    //明细dialog打开，初始化
    function OpenCheckDetail(rowid) {
        //先判断 是否是非生产用车 的情况
        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/DD/DriverReport/IFExistReportDate")',
            data:
                {
                    rowid: rowid
                },
            dataType: "json",
            success: function (jsData) {
                var banci = jsData.drinfo.BanCi;
                if (banci == "非生产用车") {
                    initNonProductFill(rowid);

                }
                else {
                    $('#FillDetailDialog').dialog('open');
                    initFill(rowid);
                }
            }
        });

    }

    //提交已勾选项
    function submitRevisitDetailForm() {
        //$('#btnDelivery').linkbutton('disable');
        var jsData = new Array();
        var i = 0;
        var rows = $('#PickTaskList').datagrid('getChecked');

        $(rows).each(function () {
            var obj = new Object();
            obj.ID = rows[i].ID;

            obj.ReportState = "已勾选";

            jsData.push(obj);
            i++;
        });

        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/DD/DriverReport/SavaPickStationReport")',
            data:
                {

                    sDeliveryDetailInfo: JSON.stringify(jsData)
                },
            dataType: "json",
            success: function (jsData) {
                $.handleJsonResult(jsData, function () {
                    Materials.length = 0;
                    $("#PickTaskList").datagrid("reload");
                    changeRevisitViewNum();
                });
            }
        });
    }

    //2019-06-13 plq 从已勾选列表中撤销某个勾选项
    function deletePickedReport(id) {
        var confirmResult = confirm("确定要撤销嘛？");
        if (!confirmResult) {
            return false;
        }
        var jsData = new Array();

        var obj = new Object();
        obj.ID = id;
        obj.ReportState = "未勾选";

        jsData.push(obj);

        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/DD/DriverReport/DeletePickedReport")',
            data:
                {
                    sDeliveryDetailInfo: JSON.stringify(jsData)
                },
            dataType: "json",
            success: function (jsData) {
                $.handleJsonResult(jsData, function () {
                    $('#CheckStationPick').dialog('close'); //关闭已勾选弹层页
                    $('#StationPickReportList').datagrid("reload");  //重新加载已勾选日报列表数据
                    $("#PickTaskList").datagrid("reload"); //重新加载分站长勾选日报列表数据
                });
            }
        });
    }



    //分站已勾选弹层页打开并查询列表数据
    function openPickReport() {

        $('#CheckStationPick').dialog('open');

        //分中心，分站  2016-4-5 新增分中心分站筛选
        EUIcombobox("#txtPickedCenter", {
            url: '@Url.Content("~/Medical/GetCenter/")',
            valueField: 'ID',
            textField: 'Name',
            //prompt: '--请选择--',
            //editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (rec) {
                var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                EUIcombobox("#txtPickedStation", {
                    url: urlstation,
                    valueField: 'ID',
                    textField: 'Name',
                    //prompt: '--请选择--',
                    editable: false,
                    OneOption: [{
                        ID: "",
                        Name: "--请选择--"
                    }]
                });
            }
        });
        EUIcombobox("#txtPickedStation", {
            url: '@Url.Content("~/Medical/GetStation?code=")',
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]
        });

        $('#StationPickReportList').datagrid({     //加载已勾选日报列表数据
            loadMsg: '数据加载中,请稍后……',
            url: '@Url.Content("~/DD/DriverReport/GetStationReportPicked")',
            height: 440,
            fitColumns: false, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            singleSelect: true,
            striped: true,
            pagination: true,//启用分页，默认每页10行
            rownumbers: false,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
            pageSize: 15,//设置 页容量5
            pageList: [10, 15, 20],//设置 页容量下拉框

            queryParams: {

                PickDate: $("#txtCheckStartTime").datebox('getValue'),
                PickedCenter: $("#txtPickedCenter").combobox('getValue'),     //分中心，分站  2016-4-5 新增分中心分站筛选
                PickedStation: $("#txtPickedStation").combobox('getValue')
            },
            frozenColumns: [[
                { field: "ID", hidden: true },
                { field: "StationName", title: "分站", width: '5%', align: "center", sortable: false, resizable: false },
                //2019-06-13 plq 增加撤销字段
                {
                    field: "deletez", title: "撤销", width: '4%', align: "center",
                    formatter: function (value, row, index) {
                        return '<a  id="adelete" class="linkURLdelete" onclick="deletePickedReport(\'' + row.ID + '\');"  href="javascript:void(0)">撤销</a>';
                    }
                },

                { field: "AgentWorkID", title: "填写人工号", width: '6%', align: "center" },
                { field: "ReportState", title: "日报状态", width: '12%', align: "center" },
                { field: "AmbulanceNumber", title: "车辆", width: '9%', align: "center" },
                { field: "ReportDate", title: "日报日期", width: '9%', align: "center", formatter: $.formatDate },
                { field: "BanCi", title: "班次", width: '6%', align: "center" },
                { field: "TaskTimes", title: "车次", width: '8%', align: "center" },
                { field: "LastModifyTime", title: "最后填写时间", width: '13%', align: "center", formatter: $.formatTime },
                { field: "LastModifier", title: "最后填写人", width: '8%', align: "center" },
                { field: "PaidMoney", title: "实际收费", width: '6%', align: "center" },
                {
                    field: "detail", title: "查看明细", width: '8%', align: "center",
                    formatter: function (value, row, index) {

                        return '<a  class="linkURLcls" onclick="OpenCheckDetail(\'' + row.ID + '\');"  href="javascript:void(0)">查看明细</a>';
                    }
                },
                       //2018-06-04 zch
            {
                field: "UnPickTask", title: "财务审核", width: '8%', align: "center",
                formatter: function (value, row, index) {
                    if (value) {
                        return value;
                    } else {
                        return '<a  id="toggleCheckID" class="linkToggle" onclick="ToggleRowSubmit(\'' + row.ID + '\');"  href="javascript:void(0)"></a>';
                    }
                }
            }
            ]],
            onLoadSuccess: function (data) {
                console.log(data);
                $('.linkURLcls').linkbutton({
                    text: '查看明细',
                    plain: true,
                    iconCls: 'icon-search'
                });
                //2018-06-04 zch
                $('.linkToggle').linkbutton({
                    text: '审核',
                    plain: true,
                    iconCls: 'icon-add',
                    toggle: true
                });
            }
        });

    }

    //2018-06-04 zch
    function ToggleRowSubmit(rowCheckID) {
        document.getElementById('toggleCheckID').disabled = true;
        //审核提交
        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/DD/DriverReport/DRPickedCheck")',
            data:
                {
                    rowCheckId: rowCheckID
                },
            dataType: "json",
            success: function (jsData) {
                $("#StationPickReportList").datagrid("reload");
                document.getElementById('toggleCheckID').disabled = false;
                $.handleJsonResult(jsData, function () {

                });
            }
        });
    }


    //查询按钮点击时 重新查询  已勾选日报列表数据
    function reopenPickReport() {
        $('#StationPickReportList').datagrid({
            pageNumber: 1,
            queryParams: {
                PickDate: $("#txtCheckStartTime").datebox('getValue'),
                PickedCenter: $("#txtPickedCenter").combobox('getValue'),     //分中心，分站  2016-4-5 新增分中心分站筛选
                PickedStation: $("#txtPickedStation").combobox('getValue')

            }
        });
    }

    function openTotalPickReportPrint() {

        var start = $("#txtCheckStartTime").datebox('getValue');
        var centerID = $("#txtPickedCenter").combobox('getValue');
        var stationID = $("#txtPickedStation").combobox('getValue');
        var url = '@Url.Content("~/BB/TJ/DriverReportStationPrint/?Start=")' + start + "&PickworkID=" + PickworkID + "&CenterID=" + centerID + "&StationID=" + stationID;
        window.open(url);

        //$('#CheckStationPick').dialog('close');
    }






</script>

<div id="CheckStationPick" class="easyui-dialog" title="分站已勾选日报" data-options="modal:true,
     collapsible:false,
     minimizable:false,
     maximizable:true,
     closed:true,
     resizable:true,
     iconCls:'icon-custom-cDelivery'" style="width: 98%; height: 520px; padding: 0px; ">

    <div id="tbba" style="padding: 5px; height: auto">
        <table style="width:99%" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td align="right" valign="middle" width="8%">勾选日期：</td>
                <td align="left" valign="middle" width="13%">
                    <input class="easyui-datebox" style="width:120px" id="txtCheckStartTime">
                </td>

                <td align="right" valign="middle" width="6%">
                    分中心：
                </td>
                <td>  <input class="easyui-combobox" style="width:100px" id="txtPickedCenter" data-options="editable:false"></td>

                <td align="right" valign="middle" width="6%">
                    分站：
                </td>
                <td>  <input class="easyui-combobox" style="width:100px" id="txtPickedStation" data-options="editable:false"></td>


                <td width="12%">
                    &nbsp;&nbsp;
                    <a href="javascript:void(0)" id="btnStationsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reopenPickReport()">查询</a>
                </td>
                <td></td>
                <td width="12%">
                    &nbsp;&nbsp;
                    <a href="javascript:void(0)" id="btnDetailz" style="width:100px" class="easyui-linkbutton" data-options="iconCls:'icon-print'" onclick="openTotalPickReportPrint()">汇总预览</a>
                </td>
            </tr>
        </table>

    </div>
    <div data-options="region:'center'" style="background: #fafafa; overflow: hidden;">
        <table id="StationPickReportList" border="0"></table>
    </div>
</div>



<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'分站长勾选车辆日报表',iconCls:'icon-custom-cPrice'">

        <div id="tbb" style="padding: 5px; height: auto">
            <table style="width:99%" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td align="right" valign="middle" width="8%">日报日期：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-datebox" style="width:100px" id="txtStartTime" data-options="editable:false">
                    </td>
                    <td align="center" valign="middle" width="5%">至</td>
                    <td align="left" valign="middle">
                        <input class="easyui-datebox" style="width: 100px" id="txtEndTime" data-options="editable:false">
                    </td>
                    <td align="right" valign="middle" width="6%">
                        分中心：
                    </td>
                    <td>  <input class="easyui-combobox" style="width:100px" id="txtPickCenter" data-options="editable:false"></td>

                    <td align="right" valign="middle" width="6%">
                        分站：
                    </td>
                    <td>  <input class="easyui-combobox" style="width:100px" id="txtPickStation" data-options="editable:false"></td>

                    <td>工号：</td>
                    <td>  <input class="easyui-textbox" style="width:100px" id="txtPickWorkID"></td>

                    <td width="12%">
                        &nbsp;&nbsp;
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="rePickTaskGrid()">查询</a>
                    </td>
                    <td></td>
                    @*<td width="12%">
                            &nbsp;&nbsp;
                            <a href="javascript:void(0)" id="btnSumbit" style="width:80px" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="submitRevisitDetailForm()">提交</a>
                        </td>*@
                    <td width="12%">
                        &nbsp;&nbsp;
                        <a href="javascript:void(0)" id="btnDetail" style="width:100px" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="openPickReport()">查看已勾选</a>
                    </td>
                </tr>

            </table>

        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="PickTaskList" border="0"></table>
        </div>
    </div>
</div>
@Html.Partial("~/Areas/DD/Views/DriverReport/DriverReportStationCheck.cshtml")
@Html.Partial("~/Areas/DD/Views/DriverReport/DriverReportStationNonProduct.cshtml")